use std::collections::HashMap;

use leptos::*;

#[allow(non_snake_case)]
#[component]
pub fn App() -> impl IntoView {
    let (count, set_count) = create_signal(String::new());
    let set_clone = set_count.clone();
    let click = move |_| {
        let client = reqwest::Client::new();
        wasm_bindgen_futures::spawn_local(async move {
            let mut hades = HashMap::new();
            hades.insert("wawa", "hahaha");
            let res = client
                .post("http://127.0.0.1:8088/greeting1")
                .json(&hades)
                .send()
                .await;
            match res {
                Err(e) => set_clone.set("你好世界".to_string()),
                Ok(res) => set_clone.set(res.text().await.unwrap()),
            }
        });
    };

    view! {
        <button on:click =click class="w-40 h-20 bg-pink-500 box-border mt-10 mx-10 rounded-md ">
        <span class="size-12 font-bold text-blue-500">"按下我就会发生变化:"</span>
        </button>
        <div>
         {count}
        </div>
    }
}
